package com.akami.recipe;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.akami.admin.SessionManager;

import xframe.conf.Constants;
import xframe.ctl.XDispatchAction;
import xframe.util.AutoMapper;
import xframe.util.CookieUtil;
import xframe.util.DynamicVar;
import xframe.util.FileManager;
import xframe.util.beans.UploadFile;
import xframe.util.db.Row;
import xframe.util.db.Transaction;
import xframe.util.UtilMaster;

public class UploadAction  extends XDispatchAction{
	public ActionForward sendRedirect( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception { 

		Row	req			=	getRequestInfo(request);
		
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
				
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################		
		
		request.setAttribute("nextPage", req.get("nextPage"));
		return mapping.findForward( "sendRedirect" ); 
	}
	
	
	public ActionForward mainImageUpload( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		
        String savePath=DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
        int sizeLimit = 10 * 1024  * 1024 ;      // 파일업로드 용량 제한.. 2Mb
        AutoMapper mapper = null;
        Row	req		= new Row();
        System.out.println("=====================");
        System.out.println(req);
        System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
				
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################

        HttpSession session = request.getSession();
        try{
        	/**
             * @see  : Multipart를 처리하기 위해 구현된 함수로 내부 접근 함수를 통해서 hashmap으로 받을 수 있다.
             * 예>  AutoMapper mapper = new AutoMapper(request, savePath,sizeLimit, "euc-kr", Constant.UPLOAD_currentTimeMillis_NAME_RULE);
             * @param request  : HttpServletRequest
             * @param savePath  : 파일이 저장될 위치
             * @param pathPlus  : 파일이 저장될 위치의  sub 디렉토리명
             * @param sizeLimit  : 파일의 제한용량 byte 기준(1024*1024*10=>10Mb)가된다.
             * @param request  : HttpServletRequest
             * @param request  : HttpServletRequest
             * @return :  생성자 함수
             */         	
        mapper	=	new AutoMapper(request, savePath, "recipe", sizeLimit, Constants.UPLOAD_currentTimeMillis_NAME_RULE);
        req		= mapper.getMutlpartParam();
        System.out.println("*****req==>"+req);
        long curentTime = 0;
        curentTime	=	System.currentTimeMillis();
        req.put("file_index", curentTime+"");
        
        //System.out.println("curentTime;"+curentTime);
        //이미지는 하나씩만 업로드 되므로 아래의 구조는 영향이 없다.
		ArrayList fileInfo = mapper.getFiles();
        for(int i =0; i < fileInfo.size() ; i++){
            UploadFile file =(UploadFile) fileInfo.get(i);
            req.put("file_ext", file.getExe());
            req.put("file_name", file.getFileName());
            req.put("file_path", StringUtils.remove(file.getDirectoryPath(), DynamicVar.get("board.boardRoot")));
            req.put("file_path", StringUtils.remove(req.getString("file_path")," "));
            req.put("size", file.getSize()+"");
            req.put("re_file_name", file.getRenamedFile());
            req.put("file_type", "0"); // 메인 레시피 사진
            req.put("saved_dir", file.getDirectoryPath());
        }
        

			
			BufferedImage inImage = null;
		    int width 	= 	-1;
		    int height	=	-1;
		    try{
		    	System.out.println("*****==>"+req.get("saved_dir")+"/"+req.get("re_file_name"));
		        inImage = ImageIO.read(new File(req.get("saved_dir")+"/"+req.get("re_file_name")));
		        if( inImage != null ){
		            width = inImage.getWidth();
		            height = inImage.getHeight();
		        }
		        req.put("width",width+"");
		        req.put("height",height+"");
		    } catch (Exception e) {
		        e.printStackTrace();
		    }
			
        	req.put("imagepath", req.get("file_path")+"/"+req.get("saved_file_name"));
        	req.put("session_id", session.getId());
        	req.put("reg_email", session.getAttribute("s_email"));
        	

        	
        	try{		
        		// 디비연결 시작
        		Transaction.start(request);		
        		
        		
        		String queryName	=	"recipe.mainImageUpload";		
        		String	query 	=	mappingQuery(req, queryName);
        		String[] preparedIndex = {
        				"file_index",
        				"recipe_pk",
        				"file_type",
        				"file_name",
        				"re_file_name",
        				"size",
        				"file_ext",
        				"width",
        				"height",
        				"saved_dir",
        				"file_path",
        				"reg_email",
        				"session_id"           
        				};
        		//PreparedStatement  실행
        		preparedExecuteUpdate(request, req, preparedIndex, query);		
        		
        		
        		//전체게시물의 갯수를 토대로 다시 쿼리를 날려서 원하는 데이터만 받아온다.		
        		String 	listQueryName	=	"recipe.attachementUploadSelect";
        		String	listQuery 		=	mappingQuery(req, listQueryName);	

        		simpleExecuteQuery(request, listQuery, listQueryName);	
        		
        		//디비연결 종
                Transaction.end(request);
        												
        		}catch(Exception e){
        			e.printStackTrace();
        			Transaction.rollback(request, response);
        			req.put("system_error", e.getMessage());
        			return mapping.findForward( "system_error" );			
        		} 
        		        	
        	
        	
        	//System.out.println("imagepath : "+req.get("file_path")+"/"+req.get("saved_file_name"));
        	req.put("message", "업로드완료");
        }catch (SizeLimitExceededException ex) {
        	//제한 용량이 넘으면 에러 발생!
        	req.put("message", "파일 용량을 "+sizeLimit/1024/1024+" Mb 이하로 조정해주십시오. 용량이 초과 되었습니다.");
        		
		}
        request.setAttribute("request", req);
		return mapping.findForward("attachementUploadSelect");
	}
        
	public ActionForward mainImageSet( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		
		Row	req			=	getRequestInfo(request);
		

		try{
			// 디비연결 시작
			Transaction.start(request);		
			
			HttpSession session = request.getSession();
			req.put("s_name", session.getAttribute("name"));
			req.put("s_email", session.getAttribute("email"));

			String queryName	=	"recipe.setmainImageUpload";		
			String	query 	=	mappingQuery(req, queryName);
			String[] preparedIndex = {
					"main_img_pk",
					"recipe_pk"
			};
			//PreparedStatement  실행
			preparedExecuteUpdate(request, req, preparedIndex, query);		

	
			//디비연결 종
	        Transaction.end(request);
        
			req.put("SUCCESS_FAIL", "SUCCESS");
			req.put("MESSAGE", "수정 되었습니다..");
			
			return mapping.findForward( "success_fail" );         
													
			}catch(Exception e){
				e.printStackTrace();
				Transaction.rollback(request, response);
				req.put("system_error", e.getMessage());
				req.put("SUCCESS_FAIL", "FAIL");
				req.put("MESSAGE", "수정오류");
				return mapping.findForward( "success_fail" );			
			}   

	}
	
	public ActionForward stepImageUpload( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		
		String savePath=DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
		int sizeLimit = 10 * 1024  * 1024 ;      // 파일업로드 용량 제한.. 2Mb
		AutoMapper mapper = null;
		Row	req		= new Row();
		System.out.println("=====================");
		System.out.println(req);
		System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
		
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################
		
		HttpSession session = request.getSession();
		try{
			/**
			 * @see  : Multipart를 처리하기 위해 구현된 함수로 내부 접근 함수를 통해서 hashmap으로 받을 수 있다.
			 * 예>  AutoMapper mapper = new AutoMapper(request, savePath,sizeLimit, "euc-kr", Constant.UPLOAD_currentTimeMillis_NAME_RULE);
			 * @param request  : HttpServletRequest
			 * @param savePath  : 파일이 저장될 위치
			 * @param pathPlus  : 파일이 저장될 위치의  sub 디렉토리명
			 * @param sizeLimit  : 파일의 제한용량 byte 기준(1024*1024*10=>10Mb)가된다.
			 * @param request  : HttpServletRequest
			 * @param request  : HttpServletRequest
			 * @return :  생성자 함수
			 */         	
			mapper	=	new AutoMapper(request, savePath, "recipe", sizeLimit, Constants.UPLOAD_currentTimeMillis_NAME_RULE);
			req		= mapper.getMutlpartParam();
			System.out.println("288*****req==>"+req);
			//long curentTime = 0;
			//curentTime	=	System.currentTimeMillis();
			//req.put("file_index", curentTime+"");
			
			//System.out.println("curentTime;"+curentTime);
			//이미지는 하나씩만 업로드 되므로 아래의 구조는 영향이 없다.
			ArrayList fileInfo = mapper.getFiles();
			for(int i =0; i < fileInfo.size() ; i++){
				UploadFile file =(UploadFile) fileInfo.get(i);
				req.put("file_ext", file.getExe());
				req.put("file_name", file.getFileName());
				req.put("file_path", StringUtils.remove(file.getDirectoryPath(), DynamicVar.get("board.boardRoot")));
				req.put("file_path", StringUtils.remove(req.getString("file_path")," "));
				req.put("size", file.getSize()+"");
				req.put("re_file_name", file.getRenamedFile());
				req.put("saved_dir", file.getDirectoryPath());
			}
			
			
			
			BufferedImage inImage = null;
			int width 	= 	-1;
			int height	=	-1;
			try{
				System.out.println("*****==>"+req.get("saved_dir")+"/"+req.get("re_file_name"));
				inImage = ImageIO.read(new File(req.get("saved_dir")+"/"+req.get("re_file_name")));
				if( inImage != null ){
					width = inImage.getWidth();
					height = inImage.getHeight();
				}
				req.put("width",width+"");
				req.put("height",height+"");
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			req.put("imagepath", req.get("file_path")+"/"+req.get("saved_file_name"));
			req.put("session_id", session.getId());
			req.put("reg_email", session.getAttribute("s_email"));
			
			
			System.out.println("330*****==>"+req);
			try{		
				// 디비연결 시작
				Transaction.start(request);		
				
				
				String queryName	=	"recipe.attachementUpload";		
				String	query 	=	mappingQuery(req, queryName);
				if(fileInfo.size() > 0){
					String[] preparedIndex = {
							"recipe_pk",
							"file_name",
							"re_file_name",
							"size",
							"file_ext",
							"width",
							"height",
							"saved_dir",
							"file_path",
							"reg_email",
							"session_id" ,
							"file_index"
					};
					//PreparedStatement  실행
					preparedExecuteUpdate(request, req, preparedIndex, query);		
					
				}else{
					String[] preparedIndex = {
							"recipe_pk",
							"reg_email",
							"step_recipe_content" ,
							"session_id" ,
							"file_index"
					};	
					//PreparedStatement  실행
					preparedExecuteUpdate(request, req, preparedIndex, query);		
					
				}
				
				
				//전체게시물의 갯수를 토대로 다시 쿼리를 날려서 원하는 데이터만 받아온다.		
				String 	listQueryName	=	"recipe.attachementUploadStepSelect";
				String	listQuery 		=	mappingQuery(req, listQueryName);	
				
				simpleExecuteQuery(request, listQuery, listQueryName);	
				
				//디비연결 종
				Transaction.end(request);
				
			}catch(Exception e){
				e.printStackTrace();
				Transaction.rollback(request, response);
				req.put("system_error", e.getMessage());
				return mapping.findForward( "system_error" );			
			} 
			
			
			
			//System.out.println("imagepath : "+req.get("file_path")+"/"+req.get("saved_file_name"));
			req.put("message", "업로드완료");
		}catch (SizeLimitExceededException ex) {
			//제한 용량이 넘으면 에러 발생!
			req.put("message", "파일 용량을 "+sizeLimit/1024/1024+" Mb 이하로 조정해주십시오. 용량이 초과 되었습니다.");
			
		}
		request.setAttribute("request", req);
		return mapping.findForward("attachementUploadStepSelect");
	}
	
	public ActionForward addNewStep( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		
		String savePath=DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
		int sizeLimit = 10 * 1024  * 1024 ;      // 파일업로드 용량 제한.. 2Mb
		AutoMapper mapper = null;
		Row	req		= new Row();
		System.out.println("=====================");
		System.out.println(req);
		System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
		
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################
		
		HttpSession session = request.getSession();
		try{
			/**
			 * @see  : Multipart를 처리하기 위해 구현된 함수로 내부 접근 함수를 통해서 hashmap으로 받을 수 있다.
			 * 예>  AutoMapper mapper = new AutoMapper(request, savePath,sizeLimit, "euc-kr", Constant.UPLOAD_currentTimeMillis_NAME_RULE);
			 * @param request  : HttpServletRequest
			 * @param savePath  : 파일이 저장될 위치
			 * @param pathPlus  : 파일이 저장될 위치의  sub 디렉토리명
			 * @param sizeLimit  : 파일의 제한용량 byte 기준(1024*1024*10=>10Mb)가된다.
			 * @param request  : HttpServletRequest
			 * @param request  : HttpServletRequest
			 * @return :  생성자 함수
			 */         	
			mapper	=	new AutoMapper(request, savePath, "recipe", sizeLimit, Constants.UPLOAD_currentTimeMillis_NAME_RULE);
			req		= mapper.getMutlpartParam();
			System.out.println("427*****req==>"+req);
			long curentTime = 0;
			curentTime	=	System.currentTimeMillis();
			req.put("file_index", curentTime+"");
			
			//System.out.println("curentTime;"+curentTime);
			//이미지는 하나씩만 업로드 되므로 아래의 구조는 영향이 없다.
			ArrayList fileInfo = mapper.getFiles();
			for(int i =0; i < fileInfo.size() ; i++){
				UploadFile file =(UploadFile) fileInfo.get(i);
				req.put("file_ext", file.getExe());
				req.put("file_name", file.getFileName());
				req.put("file_path", StringUtils.remove(file.getDirectoryPath(), DynamicVar.get("board.boardRoot")));
				req.put("file_path", StringUtils.remove(req.getString("file_path")," "));
				req.put("size", file.getSize()+"");
				req.put("re_file_name", file.getRenamedFile());
				req.put("saved_dir", file.getDirectoryPath());
			}
			
			
			
			BufferedImage inImage = null;
			int width 	= 	-1;
			int height	=	-1;
			try{
				System.out.println("*****==>"+req.get("saved_dir")+"/"+req.get("re_file_name"));
				inImage = ImageIO.read(new File(req.get("saved_dir")+"/"+req.get("re_file_name")));
				if( inImage != null ){
					width = inImage.getWidth();
					height = inImage.getHeight();
				}
				req.put("width",width+"");
				req.put("height",height+"");
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			req.put("imagepath", req.get("file_path")+"/"+req.get("saved_file_name"));
			req.put("session_id", session.getId());
			req.put("reg_email", session.getAttribute("s_email"));
			
			
			System.out.println("330*****==>"+req);
			try{		
				// 디비연결 시작
				Transaction.start(request);		
				
				String queryName	=	"recipe.addNewStep";		
				String	query 	=	mappingQuery(req, queryName);
				String[] preparedIndex = {
						"file_index",
						"recipe_pk",
						"file_name",
						"re_file_name",
						"size",
						"file_ext",
						"width",
						"height",
						"saved_dir",
						"file_path",
						"step_recipe_content",
						"reg_email",
						"session_id"
				};
				//PreparedStatement  실행
				preparedExecuteUpdate(request, req, preparedIndex, query);		
				
				
				//전체게시물의 갯수를 토대로 다시 쿼리를 날려서 원하는 데이터만 받아온다.		
				String 	listQueryName	=	"recipe.attachementUploadStepSelect";
				String	listQuery 		=	mappingQuery(req, listQueryName);	
				
				simpleExecuteQuery(request, listQuery, listQueryName);	
				
				//디비연결 종
				Transaction.end(request);
				
			}catch(Exception e){
				e.printStackTrace();
				Transaction.rollback(request, response);
				req.put("system_error", e.getMessage());
				return mapping.findForward( "system_error" );			
			} 
			
			
			
			//System.out.println("imagepath : "+req.get("file_path")+"/"+req.get("saved_file_name"));
			req.put("message", "업로드완료");
		}catch (SizeLimitExceededException ex) {
			//제한 용량이 넘으면 에러 발생!
			req.put("message", "파일 용량을 "+sizeLimit/1024/1024+" Mb 이하로 조정해주십시오. 용량이 초과 되었습니다.");
			
		}
		request.setAttribute("request", req);
		return mapping.findForward("attachementUploadStepSelect");
	}
	
	public ActionForward list( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {

			Row	req			=	getRequestInfo(request);
				

			try{
				// 디비연결 시작
				Transaction.start(request);		
				
				HttpSession session = request.getSession();
				req.put("s_name", session.getAttribute("name"));
				req.put("s_email", session.getAttribute("email"));
				
		        // 전체 게시물 갯수
				String totalQueryName	=	"codeMaster.codeCnt";		
				String	totalQuery 	=	mappingQuery(request, totalQueryName);
				
				simpleExecuteQueryGetOneRow(request, totalQuery, totalQueryName);
				
				Row	SUM_LIST	=	(Row)request.getAttribute(totalQueryName);			
				req.put("TOTAL", SUM_LIST.getString("TOTAL"));					
				int start_row 	=	0;
				int page		=	0;
				//페이지 파라미터 점검
				//첫페이지는 파라미터가 없으므로 0이나 1로 셋팅한다.
				if(req.get("page") ==null || ((String)req.get("page")).trim().length() == 0 ){
					page	=	1;
				}else  {
					try{
						page	=	Integer.parseInt(((String)req.get("page")));
					}catch(Exception e){
						page	=	1;
					}
				}
				start_row	=	(page	-	1)	*	10;
				req.put("start_row", start_row+"");
				req.put("page", page+"");
				
				//전체게시물의 갯수를 토대로 다시 쿼리를 날려서 원하는 데이터만 받아온다.		
				String 	listQueryName	=	"codeMaster.selectCode";
				String	listQuery 		=	mappingQuery(req, listQueryName);	
		
				simpleExecuteQuery(request, listQuery, listQueryName);												
		
				//디비연결 종
		        Transaction.end(request);
	        
			}catch(Exception e){
				e.printStackTrace();
				Transaction.rollback(request, response);
				req.put("system_error", e.toString());
				return mapping.findForward( "system_error" );
			}        
			
		return mapping.findForward("attachementUploadSelect");
	}
	
	
	public ActionForward deleteFile( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		request.setCharacterEncoding("UTF-8");
		String savePath	=	DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
		Row	req			=	getRequestInfo(request);
        System.out.println("====deleteFile=================");
        System.out.println(req);
        System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
				
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################


		try{
			// 디비연결 시작
			Transaction.start(request);		
			
			HttpSession session = request.getSession();
			req.put("session_id", session.getId());
	        // 전체 게시물 갯수
			String queryName	=	"recipe.getFileInfo";		
			String	query 	=	mappingQuery(request, queryName);
			
    		String separator  = System.getProperty("file.separator");
    		Row file_info= simpleExecuteQueryGetOneRow(request, query, queryName);		
    		System.out.println(file_info.getString("saved_dir")+separator+file_info.get("re_file_name"));
    		File file = new File(file_info.getString("saved_dir")+separator+file_info.get("re_file_name"));
			file.delete();
			
    		queryName	=	"recipe.deleteFileInfo";		
    		query 	=	mappingQuery(req, queryName);
    		String[] preparedIndex = {
    				"file_index"
    				};
    		//PreparedStatement  실행
    		preparedExecuteUpdate(request, req, preparedIndex, query);	

    		//전체게시물의 갯수를 토대로 다시 쿼리를 날려서 원하는 데이터만 받아온다.		
    		queryName	=	"recipe.attachementUploadSelect";
    		query 		=	mappingQuery(req, queryName);	

    		simpleExecuteQuery(request, query, queryName);	    		
    		
			//디비연결 종
	        Transaction.end(request);
	        req.put("message", "삭제완료");
		}catch(Exception e){
			e.printStackTrace();
			Transaction.rollback(request, response);
			req.put("system_error", e.toString());
			return mapping.findForward( "system_error" );
		}        
		
        return mapping.findForward( "attachementUploadSelect" );       
	}
	
	public ActionForward deleteFileAndOrder( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		request.setCharacterEncoding("UTF-8");
		String savePath	=	DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
		Row	req			=	getRequestInfo(request);
		System.out.println("====deleteFile=================");
		System.out.println(req);
		System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
		
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################
		
		
		try{
			// 디비연결 시작
			Transaction.start(request);		
			
			HttpSession session = request.getSession();
			req.put("session_id", session.getId());
			// 전체 게시물 갯수
			String queryName	=	"recipe.getFileInfo";		
			String	query 	=	mappingQuery(request, queryName);
			
			String separator  = System.getProperty("file.separator");
			Row file_info= simpleExecuteQueryGetOneRow(request, query, queryName);		
			System.out.println(file_info.getString("saved_dir")+separator+file_info.get("re_file_name"));
			File file = new File(file_info.getString("saved_dir")+separator+file_info.get("re_file_name"));
			file.delete();
			
			queryName	=	"recipe.deleteFileInfo";		
			query 	=	mappingQuery(req, queryName);
			String[] preparedIndex = {
					"file_index"
			};
			//PreparedStatement  실행
			preparedExecuteUpdate(request, req, preparedIndex, query);	
			
			
			Transaction.end(request);
			req.put("SUCCESS_FAIL", "SUCCESS");
			req.put("MESSAGE", "삭제완료");
		}catch(Exception e){
			e.printStackTrace();
			Transaction.rollback(request, response);
			req.put("system_error", e.getMessage());
			req.put("SUCCESS_FAIL", "FAIL");
			req.put("MESSAGE", "수정오류");
			return mapping.findForward( "system_error" );
		}        
		
		return mapping.findForward( "success_fail" );        
	}
	
	public ActionForward deleteImgToNull( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		request.setCharacterEncoding("UTF-8");
		String savePath	=	DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
		Row	req			=	getRequestInfo(request);
		System.out.println("====deleteFile=================");
		System.out.println(req);
		System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
		
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################
		
		
		try{
			// 디비연결 시작
			Transaction.start(request);		
			
			HttpSession session = request.getSession();
			req.put("session_id", session.getId());
			// 전체 게시물 갯수
			String queryName	=	"recipe.getFileInfo";		
			String	query 	=	mappingQuery(request, queryName);
			
			String separator  = System.getProperty("file.separator");
			Row file_info= simpleExecuteQueryGetOneRow(request, query, queryName);		
			System.out.println(file_info.getString("saved_dir")+separator+file_info.get("re_file_name"));
			File file = new File(file_info.getString("saved_dir")+separator+file_info.get("re_file_name"));
			file.delete();
			
			queryName	=	"recipe.deleteImgToNull";		
			query 	=	mappingQuery(req, queryName);
			String[] preparedIndex = {
					"file_index"
			};
			//PreparedStatement  실행
			preparedExecuteUpdate(request, req, preparedIndex, query);	
			
			//디비연결 종
			Transaction.end(request);
			req.put("SUCCESS_FAIL", "SUCCESS");
			req.put("MESSAGE", "삭제완료");
		}catch(Exception e){
			e.printStackTrace();
			Transaction.rollback(request, response);
			req.put("system_error", e.getMessage());
			req.put("SUCCESS_FAIL", "FAIL");
			req.put("MESSAGE", "수정오류");
			return mapping.findForward( "system_error" );
		}        
		
		return mapping.findForward( "success_fail" );       
	}
	
	
	public ActionForward descUpdate( 	ActionMapping       mapping,
			ActionForm          form,
			HttpServletRequest  request,
			HttpServletResponse response ) throws Exception {
		
		String savePath	=	DynamicVar.get("board.uploadDir");	// 저장할 디렉토리 (절대경로)
		Row	req			=	getRequestInfo(request);
		System.out.println("====descUpdate=================");
		System.out.println(req);
		System.out.println("=====================");
		//#################################################################
		//##권한 체크
		Row messageMap = new Row();
		messageMap.put("nextPage", request.getContextPath());
		messageMap.put("errorMessage", "세션이 종료 되었거나 잘못된 접근입니다.");
		messageMap.put("beforePage", request.getHeader( "REFERER"));
		messageMap.put("link_name", "로그인");
		messageMap.put("parameter", req);		
		
		if(SessionManager.sessioncheck(request, response, req,messageMap)){ 
			request.setAttribute("messageMap", messageMap);	
			return mapping.findForward( "sessionError" );
		}
		//#################################################################
		
		
		try{
			// 디비연결 시작
			Transaction.start(request);		
			
			HttpSession session = request.getSession();
			req.put("session_id", session.getId());
			

			
			String queryName	=	"recipe.stepDescUpdate";		
			String query 	=	mappingQuery(request, queryName);			
				String[] preparedIndex = {
						"step_recipe_content",
						"file_index"
				};
				//PreparedStatement  실행
				preparedExecuteUpdate(request, req, preparedIndex, query);	
			
			
			//디비연결 종
			Transaction.end(request);
			req.put("SUCCESS_FAIL", "SUCCESS");
			req.put("MESSAGE", "수정 되었습니다..");
			
			return mapping.findForward( "success_fail" );         
													
			}catch(Exception e){
				e.printStackTrace();
				Transaction.rollback(request, response);
				req.put("system_error", e.getMessage());
				req.put("SUCCESS_FAIL", "FAIL");
				req.put("MESSAGE", "수정오류");
				return mapping.findForward( "success_fail" );			
			}   
	}
	
}
